package com.wskj.insuranceweb.reporter.controller;

import com.wskj.insuranceweb.reporter.pojo.Client;
import com.wskj.insuranceweb.reporter.pojo.Contract;
import com.wskj.insuranceweb.reporter.pojo.Employee;
import com.wskj.insuranceweb.reporter.pojo.Users;
import com.wskj.insuranceweb.reporter.service.ClientService;
import com.wskj.insuranceweb.reporter.service.UserService;
import com.wskj.insuranceweb.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService service;
    @Autowired
    private ClientService clientService;


    @RequestMapping("/list1")
    public String list(){
        return "user/list";
    }
    @RequestMapping("/list")
    @ResponseBody
    public List<Users> list(String phone , String kname){
        return service.findAllUsers(phone,kname);
    }

    @RequestMapping("/findClient")
    public String findClient(String id , Model model){
        Client client = clientService.findClient(id);
        model.addAttribute("client",client);
        return "user/lookClient";
    }
    @RequestMapping("/addusers")
    public String addUser(){
        return "user/addUser";
    }
    @RequestMapping("/adduser")
    public String addUser(Users user,Client client,HttpServletRequest request){
        System.out.println(user);

        Employee e = (Employee) request.getSession().getAttribute("employee");
        user.setEmployeename(e.getName());
        service.addUser(user);
        System.out.println(client);
        clientService.addClient(client);
        return "user/list";
    }

    @RequestMapping("/findContract")
    public String find(Model model){
        Contract contract = service.findContract();
        model.addAttribute("contract",contract);
        return "user/contract";
    }
}
